import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
   define: {
    global: 'globalThis',
  },
  server: {
    port: 3000,
    proxy: {
        '/api': {
        target: 'http://localhost:8082',
        changeOrigin: true
      },
      // 代理IAM认证接口
      '/huawei-iam': {
        target: 'https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/huawei-iam/, '')
      },
      // 代理IoT平台接口
      '/huawei-iot': {
        target: 'https://iotda.cn-north-4.myhuaweicloud.com/v5/iot',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/huawei-iot/, '')
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['vue', 'vue-router', 'pinia'],
          element: ['element-plus', '@element-plus/icons-vue'],
          network: ['axios', 'sockjs-client', 'webstomp-client']
        }
      }
    }
  },
  base: './'
}) 